<?php

namespace App\Admin\Actions\Order;

use Encore\Admin\Actions\Action;
use Illuminate\Http\Request;
use App\Imports\PddImport;
use App\Models\Order;
use Excel;
use DB;

class ImportPdd extends Action
{
    protected $selector = '.import-pdd';

    public function handle(Request $request)
    {
        // DB::table('orders')->truncate();

        // 执行导入
        Excel::import(new PddImport, $request->file('file'));

        return $this->response()->success('导入成功')->refresh();
    }

    public function html()
    {
        return <<<HTML
        <a class="btn btn-sm btn-default import-pdd">导入拼多多订单</a>
HTML;
    }

    public function form()
    {
        $this->file('file', '请选择文件')->help('请上传要导入的拼多多订单');
    }
}